package com.woniu.core.service.Impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.woniu.core.entity.CoreTender;
import com.woniu.core.mapper.CoreTenderMapper;
import com.woniu.core.mapper.CoreUserMapper;
import com.woniu.core.service.CoreTenderService;
import com.woniu.util.utils.HttpResult;
import com.woniu.util.utils.RequestResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class CoreTenderServiceImpl implements CoreTenderService {
    @Autowired
    private CoreTenderMapper coreTenderMapper;
    @Autowired
    private CoreUserMapper coreUserMapper;

    @Override
    public HttpResult<?> selectTender(RequestResult<String> param) {
        try {
            String userCoreId = coreUserMapper.selectUserCoreIdByUserAccount(param.getData());
            PageHelper.startPage(param.getPageNum(), param.getPageSize());
            List<CoreTender> tenders = coreTenderMapper.selectTender(userCoreId);
            PageInfo<CoreTender> pageInfo = new PageInfo<>(tenders);
            return new HttpResult<>().ok(pageInfo);
        } catch (Exception e) {
            e.printStackTrace();
            return new HttpResult<>().fail();
        }
    }

}
